<template>
<div>
    <home-header></home-header>
    <home-swiper :swiper="swiperList"></home-swiper>
    <home-icons :iconList="iconList"></home-icons>
    <home-recommend :recommendList="recommendList"></home-recommend>
</div>
</template>
<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      lastCity: ''
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend
  },
  computed: {
    ...mapState(['city'])
  },
  mounted () {
    this.getHomeAxios()
    this.lastCity = this.city
  },
  methods: {
    getHomeInfo (res) {
      let ret = res.data.data
      this.swiperList = ret.swiperList
      this.iconList = ret.iconList
      this.recommendList = ret.recommendList
    },
    getHomeAxios () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfo)
        .catch(function (e) {})
    }
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.getHomeAxios()
      this.lastCity = this.city
    }
  }
}
</script>
<style>
</style>
